import { API } from '../config/config';

import HTTP from '../utils/http';

const COURSE = API.COURSE;

class CourseService extends HTTP {
  async getCourseData() {
    return new Promise((resolve, reject) => {
      this.axiosGet({
        url: COURSE.GET_COURSE_DATA,
        success: (res) => {
          resolve(res);
        },
        error: (err) => {
          alert('网络请求错误');
          window.location.reload();
        }
      })
    })
  }

  async getCourseField () {
    return new Promise((resolve, reject) => {
      this.axiosGet({
        url: COURSE.GET_COURSE_FIELD,
        success(res){
          resolve(res);
        },
        error(error){
          alert('网络请求错误');
          window.location.reload();
        }
      })
    })
  }

  async changeCourseField (data) {
    return new Promise((resolve, reject) => {
      this.axiosPost({
        url: COURSE.CHANGE_COURSE_FIELD,
        data: data,
        success(res){
          resolve(res);
        },
        error(error){
          alert('网络请求错误');
          window.location.reload();
        }
      })
    })
  }

  async changeCourseStatus (data) {
    return new Promise((resolve, reject) => {
      this.axiosPost({
        url: COURSE.CHANGE_COURSE_STATUS,
        data: data,
        success(res){
          resolve(res);
        },
        error(error){
          alert('网络请求错误');
          window.location.reload();
        }
      })
    })
  }

}

export default CourseService;